package com.geekchique.runningbuddy.activity;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import com.geekchique.runningbuddy.provider.RunBuddyCP;

public class DebugContentProvider extends Activity {

	public static final String	LOG_TAG			= "unitTest";

	public static final String	ROUTE_NAME		= "Green PArk";

	public static final long	ROUTE_LATITUDE	= 55851100;

	@Override
	protected void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		//testGettingRouteName();
		//testGettingRouteLatitude();
		//testGettingASingleRoute();
		//testInsertingEmptyRoute();
	}

	public void testInsertingEmptyRoute() {
		Uri uri = getContentResolver().insert(RunBuddyCP.Routes.CONTENT_URI, null);
		if (uri != null) {
			Log.i(LOG_TAG, "testInsertingEmptyRoute was successful");
		} else {
			Log.w(LOG_TAG, "testInsertingEmptyRoute was unsuccessful");
		}
	}

	public void testGettingRouteName() {
		String routeName = null;

		Cursor cur = getContentResolver().query(RunBuddyCP.Routes.CONTENT_URI, new String[] { RunBuddyCP.Routes.NAME }, null, null,
				null);

		if (cur != null) {
			cur.first();
			routeName = cur.getString(0);

			if (routeName.compareTo(ROUTE_NAME) == 0) {
				Log.i(LOG_TAG, "testGettingRouteName was successful");
			} else {
				Log.w(LOG_TAG, "testGettingRouteName was unsuccessful: " + routeName + " " + ROUTE_NAME);
			}
		}
	}

	public void testGettingRouteLatitude() {
		long routeLatitude = 0;

		Cursor cur = getContentResolver().query(RunBuddyCP.Routes.CONTENT_URI, new String[] { RunBuddyCP.Routes.LATITUDE }, null,
				null, RunBuddyCP.Routes.DEFAULT_SORT_ORDER);

		if (cur != null) {
			cur.first();
			routeLatitude = cur.getLong(0);
			if (ROUTE_LATITUDE == routeLatitude) {
				Log.i(LOG_TAG, "testGettingRouteLatitude was successful");
			} else {
				Log.w(LOG_TAG, "testGettingRouteLatitude was unsuccessful: " + routeLatitude + " " + ROUTE_LATITUDE);
			}
		}
	}

	public void testGettingASingleRoute() {
		long routeLatitude = 0;

		Cursor cur = getContentResolver().query(RunBuddyCP.Routes.CONTENT_URI.buildUpon().appendPath("1").build(),
				new String[] { RunBuddyCP.Routes.NAME, RunBuddyCP.Routes.LATITUDE }, null, null,
				RunBuddyCP.Routes.DEFAULT_SORT_ORDER);

		if (cur != null) {
			cur.first();
			String routeName = cur.getString(0);
			routeLatitude = cur.getLong(1);
			if (ROUTE_LATITUDE == routeLatitude && (routeName.compareTo(ROUTE_NAME) == 0)) {
				Log.i(LOG_TAG, "testGettingSingleRoute was successfult");
			} else {
				Log
						.w(LOG_TAG, "testGettingSingleRoute was unsuccessful: " + routeLatitude + " " + ROUTE_LATITUDE + " "
								+ routeName);
			}
		}
	}

}